<?php include HEADER; ?>
<?php
	$trangthai_search = (isset($_REQUEST['trangthai'])) ? $_REQUEST['trangthai'] : '';
	$idhoadon_search = (isset($_REQUEST['hoadon_id'])) ? $_REQUEST['hoadon_id'] : '';
	$phuongthuc_search = (isset($_REQUEST['phuongthuc'])) ? $_REQUEST['phuongthuc'] : '';
	$giamin_search = (isset($_REQUEST['giamin'])) ? $_REQUEST['giamin'] : '';
	$giamax_search = (isset($_REQUEST['giamax'])) ? $_REQUEST['giamax'] : '';
	$ngay_searchf = (isset($_REQUEST['ngayf'])) ? $_REQUEST['ngayf'] : '';
	$ngay_searcht = (isset($_REQUEST['ngayt'])) ? $_REQUEST['ngayt'] : '';
?>
<table id="search" style="margin-bottom:20px;">
	<tr>
		<td>
			<select id="sMaHoaDon" data-placeholder="Tìm theo mã hóa đơn..." class="chosen-select" style="width:208px;" tabindex="2">
				<option value=""></option>
			<?php
				$hoadonModel = new hoadon();
				$allHoaDon = $hoadonModel->getHoaDonByWhere('','','');
				foreach($allHoaDon as $item){
			?>
					<option value="<?php echo $item->id?>" <?php if($item->id == $idhoadon_search) echo 'selected="selected"'; ?>><?php echo $item->MaHoaDon?></option>
			<?php
				}
			?>
			</select>
			<select class="chosen-select" id="strangthai" style="width:208px;" data-placeholder="Chọn trạng thái hóa đơn..." >
				<option value=""></option>
				<option value="0" <?php if($trangthai_search=='0') echo 'selected="selected"'; ?>>Chưa xác nhận</option>
				<option value="1" <?php if($trangthai_search=='1') echo 'selected="selected"'; ?>>Đã xác nhận</option>
				<option value="2" <?php if($trangthai_search=='2') echo 'selected="selected"'; ?>>Đã thanh toán</option>
				<option value="3" <?php if($trangthai_search=='3') echo 'selected="selected"'; ?>>Hủy bởi khách hàng</option>
				<option value="4" <?php if($trangthai_search=='4') echo 'selected="selected"'; ?>>Hủy bởi Shoptivi</option>
			</select>
			
			<select id="sPhuongThuc" data-placeholder="Chọn phương thức thanh toán..." class="chosen-select" style="width:420px;" tabindex="2">
				<option value=""></option>
			<?php
				$phuongthucModel = new phuongthucthanhtoan();
				$lstpt = $phuongthucModel->getPhuongThucThanhToanByWhere('TrangThai=1','');
				foreach($lstpt as $item){
			?>
					<option value="<?php echo $item->id?>" <?php if($item->id == $phuongthuc_search) echo 'selected="selected"'; ?>><?php echo $item->MoTa?></option>
			<?php
				}
			?>
			</select>
			<br /><br />
			<input id="tGiaMin" type="text" class="text num price" placeholder="Giá trị từ..." value="<?php echo $giamin_search ?>"  />
			<input id="tGiaMax" type="text" class="text num price" placeholder="Giá trị đến..." value="<?php echo $giamax_search ?>"/>
			<input id="tNgayDatHangf" type="text" class="text tcal" placeholder="Ngày cần tìm từ..." value="<?php echo $ngay_searchf ?>"  />
			<input id="tNgayDatHangt" type="text" class="text tcal" placeholder="Ngày cần tìm đến..." value="<?php echo $ngay_searcht ?>"  />
			<span style="position:relative;top:-2px;">
				<button id="btnsearch" type="button" class="btn btn-default">
					<img src="<?php echo __URL_BASE ?>img/search.png" width="15px" />
				</button>
				<button id="btnclear" type="button" class="btn btn-default" style="margin-left: -8px;border-radius: 0 4px 4px 0;">
					<img src="<?php echo __URL_BASE ?>img/x.png" width="15px" />
				</button>
			</span>
		</td>
	
</table>
<div class="Control">
<ul style="margin-top:4px">
  <li> <a href="<?php echo __URL_BASE ?>index.php?rt=admin_order/edit"><label class="vadd">Thêm mới</label></a>  </li>
  <!--<li> <label class="vdelete" >Xóa</label> </li>
  <li> <label class="vrefresh" >Làm mới</label> </li>-->
  <li> <a class="vback" href="javascript:void(0);" onclick="window.history.go(-1);">Trở lại</a> </li>
</ul>
</div>
<table class="TableView" cellspacing="1">
<tr class="trHeader">
    <!--<td><input type="checkbox" id="chkSelectAll" onclick="checkAll(this)" /></td>-->
    <td>Mã hóa đơn</td>
    <td width="150px">Ngày đặt hàng</td>
    <td>Phương thức thanh toán</td>
    <td style="width:110px">Tổng tiền</td>
    
    <td width="150px">Trạng thái</td>
    <td width="50px"></td>
    
</tr>
<?php
    $i = 0;
	if(count($lsthd) > 0) :
		foreach($lsthd as $item){
			if($i%2==0){
?>		
				<tr class="trOdd" style="height:40px;">

            
<?php	
			}
			else{
?>
				<tr class="trEven" style="height:40px;">
<?php		
			}
?>
<!--<td ><input type="checkbox" id="chkSelect<?php echo $i?>" name="chkSelect" onclick="Check_Click(this)" /></td>-->

<td style="text-align:center;"><a href="<?php echo __URL_BASE.'index.php?rt=admin_order/edit&hoadon_id='.$item->id ?>" style="color:blue;font-weight:bold;"><?php echo $item->MaHoaDon ?></a></td>
<td style="padding: 0 10px;text-align:center;"><?php echo date('d/m/Y',strtotime($item->NgayDatHang)) ?></td>
<td><?php echo $item->MoTa?></td>
<td style="padding:0 5px;" align="right"><span><?php echo number_format($item->GiaHD,0,'','.')?> đ</span></td>

<td style="text-align:center;"><?php echo utility::getOrderStatus($item->TrangThai); ?></td>
<td align="center"><a href="<?php echo __URL_BASE.'index.php?rt=admin_order/edit&hoadon_id='.$item->id ?>"><img src="<?php echo __URL_BASE ?>images/edit.png" style="cursor:pointer;" class="edit" /></a>
<!--<a href="<?php echo __URL_BASE.'index.php?rt=admin_order/delete&hoadon_id='.$item->id ?>" onclick="return confirm('Bạn muốn xóa?');"><img src="<?php echo __URL_BASE ?>images/delete.png" /></a>--></td>

</tr>	
<?php
			$i++;
		}
	endif;
?>


</table>
<div class="Control">
<ul style="margin-top:4px">
  <li> <a href="<?php echo __URL_BASE ?>index.php?rt=admin_order/edit"><label class="vadd">Thêm mới</label></a> </li>
 <!-- <li> <label class="vdelete" >Xóa</label> </li>
  <li> <label class="vrefresh" >Làm mới</label> </li>-->
  <li> <a class="vback" href="javascript:void(0);" onclick="window.history.go(-1);">Trở lại</a> </li>
</ul>
</div>
<?php utility::getPagination_admin($pages); ?>
<?php include FOOTER; ?>
<script>
	$(document).ready(function(){
		$("#btnsearch").click(function(){
			request = '';
			if($("#sMaHoaDon").val() != '') request += '&hoadon_id='+$("#sMaHoaDon").val() ;
			if($("#strangthai").val() != '') request += '&trangthai='+$("#strangthai").val() ;
			if($("#sPhuongThuc").val() != '') request += '&phuongthuc='+$("#sPhuongThuc").val() ;
			if($("#tGiaMin").val() != '') request += '&giamin='+$("#tGiaMin").val() ;
			if($("#tGiaMax").val() != '') request += '&giamax='+$("#tGiaMax").val() ;
			if($("#tNgayDatHangf").val() != '') request += '&ngayf='+$("#tNgayDatHangf").val() ;
			if($("#tNgayDatHangt").val() != '') request += '&ngayt='+$("#tNgayDatHangt").val() ;
			location.href = '<?php echo __URL_BASE ?>index.php?rt=admin_order'+request;
		});
		
		$("#btnclear").click(function(){
			location.href = '<?php echo __URL_BASE ?>index.php?rt=admin_order';
		});
	});
</script>
